﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MainFrm.Master" AutoEventWireup="true" CodeBehind="UpdateTree.aspx.cs" Inherits="Ewts.Tree.UpdateTree" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link rel="stylesheet" href="/css/zTreeStyle.css" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="EwtsConext" runat="server">
<div id="searchDiv" >
    <span>
        <input type="radio" name="raono" id="rad1" value="load"  />&nbsp;&nbsp;&nbsp;
        Load号：<input type="text" id="txtload" class="txtno"  /> 
    </span><p>&nbsp;</p>
    <span>
        <input type="radio" name="raono" id="rad2" value="ins"  />&nbsp;&nbsp;&nbsp;
        入库单号：<input type="text" id="txtinsno" class="txtno"   /> 
    </span><p>&nbsp;</p>
    <span>
        <input type="radio" name="raono" id="rad3" value="outs"  /> &nbsp;&nbsp;&nbsp;
        出库单号：
        <input type="text"  id="txtoutsno" class="txtno"   /> 
    </span><p>&nbsp;</p>
    <div id="btnSearch" style="text-decoration:blink; color:Blue;cursor:pointer"  onclick="javascript:searchclick(-1)">点击查询</div>
</div>
<%--<input id="txtSearcheTxt" value="860000732" />
--%>
<div class="content_wrap">
	<div class="zTreeDemoBackground left">
		<ul id="treeLoad" class="ztree">
        </ul>
	</div>

<input type="hidden" id="hidrowid" value="0" />
   
</div>

<script type="text/javascript" src="/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="/js/jquery.ztree.exedit-3.5.min.js"></script>
<script type="text/javascript">
    var IDMark_A = "_a"; //860000732
    function datechange() {
        var r = confirm("是否确认修改!");
        if (r == true) {
            return true;
        } else {
            return false;
        }
    }

    function showEditDate(btn1,btn2, btn3) {
        $("#" + btn2).show();
        $("#" + btn3).show();
        $("#" + btn1).hide();
    }

    function _saveDate(btn1, btn2, btn3, datetype, selfid, oldate) {
        var newdate = $("#" + btn2).val();

        $.ajax({
            type: "post",
            url: "/ashx/tree.ashx",
            data: { date: newdate, type: datetype, id: selfid, oldate: oldate },
            dataType: "text",
            success: function (msg) {
                $("#" + btn1).html(newdate);
                $("#" + btn1).show();
                $("#" + btn2).hide();
                $("#" + btn3).hide();
                var rowid = btn1.replace("diyBtn2_", ""); // diyBtn2_
                rowid = rowid.substring(rowid.indexOf('_') + 1, rowid.len);

                $("#hidrowid").val(rowid);
                searchclick(rowid);
            }
        });
    }

  
 
    function addDiyDom(treeId, treeNode) {
        var aObj = $("#" + treeNode.tId + IDMark_A);
        var diyBtn2 = "diyBtn2_" + treeNode.id;
        var diyBtn3 = "diyBtn3_" + treeNode.id;
        var diyBtn4 = "diyBtn4_" + treeNode.id;
        var editStr = "<a id='diyBtn1_" + treeNode.id + "'";
        if (treeNode.selftstatus == -1) {
            editStr = editStr + " style='color:red;' ";
        }
        editStr = editStr + " href='" + treeNode.url + "'>" + treeNode.selfno + " &nbsp;&nbsp;" + treeNode.nwt + "</a>";
        editStr = editStr + "<div style='padding-left:40px;'>";

        //date
        var datetype = treeNode.datetype;
        if (datetype == "3") {
            datetype = "5";
            var strdate = treeNode.bardate;
            var arr = strdate.split(",");
            for (i = 0; i < arr.length; i++) {
                diyBtn2 = "diyBtn2_" + i.toString() + "_" + treeNode.id;
                diyBtn3 = "diyBtn3_" + i.toString() + "_" + treeNode.id;
                diyBtn4 = "diyBtn4_" + i.toString() + "_" + treeNode.id;
                editStr = editStr + "<span id='diyBtn2_"+ i.toString() + "_"  + treeNode.id + "' onclick=\"showEditDate('" + diyBtn2 + "','" + diyBtn3 + "','" + diyBtn4 + "')\">" + arr[i] + "</span>";
                editStr = editStr + "<input id='diyBtn3_" + i.toString() + "_" + treeNode.id + "' value='" +arr[i] + "' style='display:none;'/>";
                editStr = editStr + "<input id='diyBtn4_" + i.toString() + "_" + treeNode.id + "' type='button' onclick=\"_saveDate('" + diyBtn2 + "','" + diyBtn3 + "','" + diyBtn4 + "'," + datetype + "," + treeNode.selfid + ",'" + arr[i] + "')\" value='保存'  style='display:none;'/> ";
                editStr = editStr + " <br/> ";
            }
        }
        else {
            diyBtn2 = "diyBtn2_" + treeNode.id;
            diyBtn3 = "diyBtn3_" + treeNode.id;
            diyBtn4 = "diyBtn4_" + treeNode.id;

            editStr = editStr + "<span id='diyBtn2_" + treeNode.id + "' onclick=\"showEditDate('" + diyBtn2 + "','" + diyBtn3 + "','" + diyBtn4 + "')\">" + treeNode.createtime + "</span>";
            editStr = editStr + "<input id='diyBtn3_" + treeNode.id + "' value='" + treeNode.createtime + "' style='display:none;'/>";
            editStr = editStr + "<input id='diyBtn4_" + treeNode.id + "' type='button' onclick=\"_saveDate('" + diyBtn2 + "','" + diyBtn3 + "','" + diyBtn4 + "'," + treeNode.datetype + "," + treeNode.selfid  + ",'" + treeNode.createtime + "')\" value='保存'  style='display:none;'/> ";
        }
        editStr = editStr + "</div>";
        aObj.after(editStr);
    }

    function searchclick(rowid) {
        if (rowid == -1) {
            $("#searchDiv").dialog("close");
        }
        

        var chval = $("input[name=raono]:checked").val();
        var txtno = "";
        if ( chval != null) {
            txtno = $("input[name=raono]:checked").next().val();
        }
        else {
            alert('请选择查询单号');
            return;
        }

        if ($("#txtSearcheTxt").val() != "") {
            $.ajax({
                type: "post",
                url: "/ashx/tree.ashx",
                data: { no: txtno, notype: chval },
                dataType: "json",
                success: function (msg) {
                    if (msg == "")
                        alert('没有数据');
                    var zNodes = msg;
                    var setting = {
                        view: {
                            addDiyDom: addDiyDom
                        }
                    };

                    $.fn.zTree.init($("#treeLoad"), setting, zNodes);

                    if ($("#hidrowid").val() != -1) {
                        var treeObj = $.fn.zTree.getZTreeObj("treeLoad");
                        var treenode = treeObj.getNodeByParam("id", $("#hidrowid").val(), null);
                        treeObj.expandNode(treenode, true, true, true);
                        treeObj.selectNode(treenode);
                        
                    }

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        }
    }

    $("input[name=raono]").change(function () {
        $(".txtno").attr("disabled", "disabled");
        if ($(this).attr("checked")) {
            $(this).next().removeAttr("disabled");
        }
    });

    $("#searchDiv").dialog({
        width: 368,
        height: 180,
        resizable: false,
        position: 'center',
        dialogClass: "noClose",
        modal: true
    });

    $(".txtno").attr("disabled", "disabled");
	</script>

</asp:Content>
